<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<style type="text/css">
	#add_generalStorage .box p>label>span {
		display: inline-block;
		width: 50px;
		text-align: right;
	}
	
	#add_generalStorage input[type='text'],
	#add_generalStorage select {
		width: 125px
	}
	
	#add_generalStorage .formBox {
		padding: 0;
	}
</style>
<div class="modal fade" id="add_generalStorage" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document" style="width: 940px;">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title" id="myModalLabel">新增物品</h4>
			</div>
			<div class="box modal-body">
				<form id="searchItemForm">
					<p>
						<label>
							<span class="must">代码</span>
							<input type="text" name="itemcode" class="form-control"></input>
						</label>
						<label>
							<span class="must">名称</span>
							<input type="text" name="itemname" class="form-control"></input>
						</label>
						<label>
							<span class="must">条码</span>
							<input type="text" name="itembarcode" class="form-control"></input>
						</label>
						<label>
							<input type="hidden" name="materialMaterial" id="materialMaterial" class="form-control"></input>
						</label>
						<input class="btn btn1" type="button" value="搜索" onclick="initItemTable();">
					</p>
				</form>
				<table id="add_item_table"></table>
			</div>
			<div class="red" id="add_purchase_request_item_msg" style="text-align:center;"></div>
			<div class="modal-footer">
				<button type="button" class="btn btn_danger" data-dismiss="modal">关闭</button>
			</div>
		</div>
	</div>
</div>
<script>
	function toAddPurchaseRequestItem() {
		initItemTable();
		$('#add_generalStorage').modal('show');
	}

	var searchData = "";

	function initItemTable() {
		var columns = [{
			field: "itemcode",
			title: "物品代码"
		}, {
			field: "chinesename",
			title: "物品名称"
		}, {
			field: "articlebarcode",
			title: "物品条码"
		}, {
			field: "brand",
			title: "品牌"
		}, {
			field: "purchasingunit",
			title: "单位"
		}, {
			field: "materialmaterial",
			title: "类型",
		}, {
			field: "currentstock",
			title: "当前库存"
		}, {
			field: 'operate',
			title: '操作',
			width: '80px',
			events: listMemberOperateEvent,
			formatter: listMemberOperate
		}];
		searchData = $("#searchItemForm").serialize();
		$("#add_item_table").bootstrapTable("destroy");
		$("#add_item_table").bootstrapTable({
			columns: columns,
			data: [],
			pageSize: 10,
			pageList: [10],
			pagination: true,
			clickToSelect: true,
			uniqueId: "iteminformationid",
			sidePagination: 'server',
			pageNumber: 1,
			queryParams: function(params) {
				var currentPage = params.offset / params.limit + 1;
				var str = searchData + "&currentPage=" + currentPage + "&pageSize=" + params.limit + "&" + $("#generalStorageForm").serialize();
				return str;
			},
			url: '<%=basePath %>generalStorage/listNotAddItem'
		});
	}

	function listMemberOperate(value, row, index) {
		return [
			'<a class="addItem btn btn-xs btn1">添加</button>',
		].join('');
	}

	window.listMemberOperateEvent = {
		'click .addItem': function(e, value, row, index) {
			addItem(row);
		}
	};

	function addItem(item) {
		addToHasAddTable(item);
		$("#add_item_table").bootstrapTable('remove', {
			field: 'inteminformationid',
			values: [item.inteminformationid]
		});
	}
</script>